package movieGandalf.database;

import java.io.*;
import java.math.BigInteger;
import java.sql.*;
import java.util.LinkedList;
import java.util.List;

import movieGandalf.dbParser.*;

import movieGandalf.logicGuiConnection.*;
import movieGandalf.search.*;
import movieGandalf.dataObjects.*;

public class DBM {
	
	public void a(int[] a){
		a[0]=5;
	}
	
	public int fileRead(DataReader dr, Connection conn, String filename){
		
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
			
			return dr.read(conn, in);
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	public void readDatabase(){
		Connection conn = MovieTools.getConn();
		
		if (conn==null)
			return;
		
		try{
			fileRead(new CountriesReader(), conn, "e:\\MovieGandalf\\countries.list");
			fileRead(new LanguagesReader(), conn, "e:\\MovieGandalf\\language.list");
			fileRead(new DirectorsReader(), conn, "e:\\MovieGandalf\\directors.list");
			fileRead(new GenresReader(), conn, "e:\\MovieGandalf\\genres.list");
			fileRead(new MPAARatingsReader(), conn, "e:\\MovieGandalf\\mpaa-ratings-reasons.list");
			DataReader dr = new ActorsReader(Gender.FEMALE);
			fileRead(dr, conn, "e:\\MovieGandalf\\actresses.list");
			dr = new ActorsReader(Gender.MALE);
			fileRead(dr, conn, "e:\\MovieGandalf\\actors.list");
			fileRead(new MoviesReader(), conn, "e:\\MovieGandalf\\movies.list");
			fileRead(new CountriesAdder(), conn, "e:\\MovieGandalf\\countries.list");
			fileRead(new ColorAdder(), conn, "e:\\MovieGandalf\\color-info.list");
			fileRead(new LanguagesAdder(), conn, "e:\\MovieGandalf\\language.list");
			fileRead(new LengthsAdder(), conn, "e:\\MovieGandalf\\running-times.list");
			fileRead(new DirectorsAdder(), conn, "e:\\MovieGandalf\\directors.list");
			fileRead(new MPAARatingsAdder(), conn, "e:\\MovieGandalf\\mpaa-ratings-reasons.list");
			fileRead(new DescriptionsReader(), conn, "e:\\MovieGandalf\\plot.list");
			fileRead(new GenresAdder(), conn, "e:\\MovieGandalf\\genres.list");
			fileRead(new ActorsAdder(), conn, "e:\\MovieGandalf\\actresses.list");
			fileRead(new ActorsAdder(), conn, "e:\\MovieGandalf\\actors.list");
		}
		catch(Exception e){
		}
		finally{
			try{
				conn.close();
			}
			catch(Exception e){}
		}
	}
	
	/*
	 * 
	 * This is an example of how to search for movies.
	 * That is, with filters, as required in our search page.
	 * 
	*/
	
	/*
	MovieTools.init();
	Connection conn = MovieTools.getConn();
	List<SearchParam> sps= new LinkedList<SearchParam>();
	
	sps.add(new IsColorParam(true));
	sps.add(new LanguageIDParam(513));
	sps.add(new MaxYearParam(2000));
	sps.add(new DescriptionParam("abc"));
	
	List<Movie> movies = MovieTools.getMoviesByFilter(conn, sps);*/
	
	
	public static void main(String[] args){

		MovieTools.init();
		Connection conn = MovieTools.getConn();
		
		/*List<SearchParam> sps= new LinkedList<SearchParam>();
		
		sps.add(new DirectorNameParam("John, Mike"));
		
		sps.add(new ActorNameParam("Ever, Dia"));
		
		List<Movie> movies = MovieTools.getMoviesByFilter(conn, sps);
		
		String d = movies.get(3).getDescription();*/
		
		
		/*User user = new UserImp(null,"TestCase3","EasyPass",false);
		
		user.update();*/
		
		/*user.addWishList(BigInteger.valueOf((long) 885059));
		
		List<Movie> movies = MovieTools.getWishList(conn, BigInteger.valueOf((long) 1));
		*/
		
		MovieTools.close();
		
		return;
	}
	
}
